package com.zsqat.eshop.product.web;

import com.zsqat.eshop.product.entity.CategoryEntity;
import com.zsqat.eshop.product.service.CategoryService;
import com.zsqat.eshop.product.vo.Category2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
  @Resource
  private CategoryService categoryService;

  @GetMapping({"/", "index.html"})
  public String getIndex(Model model) {
    //获取所有的一级分类
    List<CategoryEntity> categories = categoryService.getLevel1Category();
    model.addAttribute("lstCat", categories);
    return "index";
  }

  // 从数据库或者redis获取二级，三级分类数据
  @ResponseBody
  @GetMapping("/index/category.json")
  public Map<String, List<Category2Vo>> getCategoryJson(){
    return categoryService.getCategoryJson();
  }
}
